using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Data; 
using System.Data.SqlClient; 
using System.Data.SqlTypes; 
using SolucionUtiles; 
using SolucionEntidad; 
namespace SolucionDatos 
{ 
   public class ComprobantePagoDao 
    { 
        private SqlConnection cn; 
        public ComprobantePagoDao(SqlConnection cn) 
        { 
           this.cn = cn; 
        } 
        public void insert(ComprobantePago obj)
        { 
           SqlCommand command = new SqlCommand("INSERT INTO comprobante_pago " + 
           "(numeroComprobante,tipo_comprobante_pago,idTercero) VALUES" + 
           "(@numeroComprobante,@tipo_comprobante_pago,@idTercero)", this.cn); 

command.Parameters.Add(new SqlParameter("@numeroComprobante", obj.numeroComprobante)); 
command.Parameters.Add(new SqlParameter("@tipo_comprobante_pago", obj.tipo_comprobante_pago)); 
command.Parameters.Add(new SqlParameter("@idTercero", obj.idTercero)); 
command.ExecuteNonQuery(); 
} 
  		public void update(ComprobantePago obj) 
    	{ 
        	SqlCommand command = new SqlCommand("UPDATE ComprobantePago " + 
			" SET " + 
"tipo_comprobante_pago=@tipo_comprobante_pago" + 
",idTercero=@idTercero" + 
 " WHERE " + 
"numeroComprobante=@numeroComprobante" 
,this.cn); 
command.Parameters.Add(new SqlParameter("@numeroComprobante", obj.numeroComprobante)); 
command.Parameters.Add(new SqlParameter("@tipo_comprobante_pago", obj.tipo_comprobante_pago)); 
command.Parameters.Add(new SqlParameter("@idTercero", obj.idTercero)); 
command.ExecuteNonQuery(); 
} 
       public void delete(ComprobantePago obj){ 
SqlCommand command = new SqlCommand("DELETE FROM comprobante_pago WHERE "  
 +"numeroComprobante=@numeroComprobante" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@numeroComprobante", obj.numeroComprobante)); 
command.ExecuteNonQuery(); 
} 
        public ComprobantePago get(ComprobantePago obj) 
{ 
   ComprobantePago record = null; 
    SqlCommand command = new SqlCommand("SELECT numeroComprobante,tipo_comprobante_pago,idTercero FROM comprobante_pago where " 
 +"numeroComprobante=@numeroComprobante" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@numeroComprobante", obj.numeroComprobante)); 

    SqlDataReader dr = command.ExecuteReader();
dr.Read(); 
record = new ComprobantePago(); 
if (dr["numeroComprobante"] == DBNull.Value) { record.numeroComprobante = SqlString.Null; } else { record.numeroComprobante = (String)dr["numeroComprobante"]; } 
if (dr["tipo_comprobante_pago"] == DBNull.Value) { record.tipo_comprobante_pago = SqlInt32.Null; } else { record.tipo_comprobante_pago = (Int32)dr["tipo_comprobante_pago"]; } 
if (dr["idTercero"] == DBNull.Value) { record.idTercero = SqlInt32.Null; } else { record.idTercero = (Int32)dr["idTercero"]; } 
this.cn.Close(); 
return record; 
} 
     public List<ComprobantePago> getList() 
{ 
   List<ComprobantePago> list = new List<ComprobantePago>(); 
    SqlCommand command = new SqlCommand("SELECT numeroComprobante,tipo_comprobante_pago,idTercero FROM comprobante_pago", this.cn); 
    SqlDataReader dr = command.ExecuteReader(); 
    while (dr.Read()) 
    { 
ComprobantePago obj = new ComprobantePago(); 
if (dr["numeroComprobante"] == DBNull.Value) { obj.numeroComprobante = SqlString.Null; } else { obj.numeroComprobante = (String)dr["numeroComprobante"]; } 
if (dr["tipo_comprobante_pago"] == DBNull.Value) { obj.tipo_comprobante_pago = SqlInt32.Null; } else { obj.tipo_comprobante_pago = (Int32)dr["tipo_comprobante_pago"]; } 
if (dr["idTercero"] == DBNull.Value) { obj.idTercero = SqlInt32.Null; } else { obj.idTercero = (Int32)dr["idTercero"]; } 
list.Add(obj); 
} 
return list; 
} 
} 
} 
